﻿using CDMS.BLL;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CDMS.Utilities
{
    public static class LookUpEditDataSource
    {
        static void lup_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == ButtonPredefines.Close)
                ((LookUpEdit)sender).EditValue = null;
        }

        public static void ContractStatus(LookUpEdit lup)
        {

            DataTable dt = new DataTable();
            Category_BLL category_BLL = new Category_BLL(Entities.EnumCategory.ContractStatus);
            dt = category_BLL.GetALLActivated();
            DataRow dr = dt.NewRow();
            dr["ContractStatus_ID"] = 0;
            dr["ContractStatus_Name"] = "Tất cả";
            dt.Rows.InsertAt(dr, 0);

            lup.Properties.DataSource = dt;
            lup.Properties.DisplayMember = "ContractStatus_Name";
            lup.Properties.ValueMember = "ContractStatus_ID";

            // Thêm thông tin hai cột
            DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection coll = lup.Properties.Columns;
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ContractStatus_ID", 0, "ID"));
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ContractStatus_Name", 0, "Tên trạng thái hợp đồng"));

            lup.Properties.Columns[0].Visible = false;

            lup.Properties.DropDownRows = dt.Rows.Count <= 7 ? 7 : 20;

            //  Set column widths according to their contents and resize the popup, if required.
            lup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lup.Properties.SearchMode = SearchMode.AutoComplete;

            // Specify the column against which to perform the search.
            lup.Properties.AutoSearchColumnIndex = 1;

            lup.Properties.ShowHeader = false;

            lup.Properties.Buttons.Clear();
            lup.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close)});
            lup.ButtonClick += lup_ButtonClick;
        }

        public static void ContractType(LookUpEdit lup)
        {

            DataTable dt = new DataTable();
            Category_BLL category_BLL = new Category_BLL(Entities.EnumCategory.ContractType);
            dt = category_BLL.GetALLActivated();
            DataRow dr = dt.NewRow();
            dr["ContractType_ID"] = 0;
            dr["ContractType_Name"] = "Tất cả";
            dt.Rows.InsertAt(dr, 0);

            lup.Properties.DataSource = dt;
            lup.Properties.DisplayMember = "ContractType_Name";
            lup.Properties.ValueMember = "ContractType_ID";

            // Thêm thông tin hai cột
            DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection coll = lup.Properties.Columns;
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ContractType_ID", 0, "ID"));
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("ContractType_Name", 0, "Tên loại hợp đồng"));

            lup.Properties.Columns[0].Visible = false;

            lup.Properties.DropDownRows = dt.Rows.Count <= 7 ? 7 : 20;

            //  Set column widths according to their contents and resize the popup, if required.
            lup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lup.Properties.SearchMode = SearchMode.AutoComplete;

            // Specify the column against which to perform the search.
            lup.Properties.AutoSearchColumnIndex = 1;

            lup.Properties.ShowHeader = false;

            lup.Properties.Buttons.Clear();
            lup.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close)});
            lup.ButtonClick += lup_ButtonClick;

        }

        public static void CustomerGroup(LookUpEdit lup)
        {

            DataTable dt = new DataTable();
            Category_BLL category_BLL = new Category_BLL(Entities.EnumCategory.CustomerGroup);
            dt = category_BLL.GetALLActivated();
            DataRow dr = dt.NewRow();
            dr["CustomerGroup_ID"] = 0;
            dr["CustomerGroup_Name"] = "Tất cả";
            dt.Rows.InsertAt(dr, 0);

            lup.Properties.DataSource = dt;
            lup.Properties.DisplayMember = "CustomerGroup_Name";
            lup.Properties.ValueMember = "CustomerGroup_ID";

            // Thêm thông tin hai cột
            DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection coll = lup.Properties.Columns;
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("CustomerGroup_ID", 0, "ID"));
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("CustomerGroup_Name", 0, "Tên nhóm khách hàng"));

            lup.Properties.Columns[0].Visible = false;

            lup.Properties.DropDownRows = dt.Rows.Count <= 7 ? 7 : 20;

            //  Set column widths according to their contents and resize the popup, if required.
            lup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lup.Properties.SearchMode = SearchMode.AutoComplete;

            // Specify the column against which to perform the search.
            lup.Properties.AutoSearchColumnIndex = 1;

            lup.Properties.ShowHeader = false;

            lup.Properties.Buttons.Clear();
            lup.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close)});
            lup.ButtonClick += lup_ButtonClick;

        }
        
        public static void Unit(LookUpEdit lup)
        {

            DataTable dt = new DataTable();
            Category_BLL category_BLL = new Category_BLL(Entities.EnumCategory.Unit);
            dt = category_BLL.GetALLActivated();
            DataRow dr = dt.NewRow();
            dr["Unit_ID"] = 0;
            dr["Unit_Name"] = "Tất cả";
            dt.Rows.InsertAt(dr, 0);

            lup.Properties.DataSource = dt;
            lup.Properties.DisplayMember = "Unit_Name";
            lup.Properties.ValueMember = "Unit_ID";

            // Thêm thông tin hai cột
            DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection coll = lup.Properties.Columns;
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Unit_ID", 0, "ID"));
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Unit_Name", 0, "Tên đơn vị tính"));

            lup.Properties.Columns[0].Visible = false;

            lup.Properties.DropDownRows = dt.Rows.Count <= 7 ? 7 : 20;

            //  Set column widths according to their contents and resize the popup, if required.
            lup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lup.Properties.SearchMode = SearchMode.AutoComplete;

            // Specify the column against which to perform the search.
            lup.Properties.AutoSearchColumnIndex = 1;

            lup.Properties.ShowHeader = false;

            lup.Properties.Buttons.Clear();
            lup.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close)});
            lup.ButtonClick += lup_ButtonClick;

        }
      
        public static void PaymentWay(LookUpEdit lup)
        {

            DataTable dt = new DataTable();
            Category_BLL category_BLL = new Category_BLL(Entities.EnumCategory.PaymentWay);
            dt = category_BLL.GetALLActivated();
            DataRow dr = dt.NewRow();
            dr["PaymentWay_ID"] = 0;
            dr["PaymentWay_Name"] = "Tất cả";
            dt.Rows.InsertAt(dr, 0);

            lup.Properties.DataSource = dt;
            lup.Properties.DisplayMember = "PaymentWay_Name";
            lup.Properties.ValueMember = "PaymentWay_ID";

            // Thêm thông tin hai cột
            DevExpress.XtraEditors.Controls.LookUpColumnInfoCollection coll = lup.Properties.Columns;
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("PaymentWay_ID", 0, "ID"));
            coll.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("PaymentWay_Name", 0, "Tên các thanh toán"));

            lup.Properties.Columns[0].Visible = false;

            lup.Properties.DropDownRows = dt.Rows.Count <= 7 ? 7 : 20;

            //  Set column widths according to their contents and resize the popup, if required.
            lup.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lup.Properties.SearchMode = SearchMode.AutoComplete;

            // Specify the column against which to perform the search.
            lup.Properties.AutoSearchColumnIndex = 1;

            lup.Properties.ShowHeader = false;

            lup.Properties.Buttons.Clear();
            lup.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close)});
            lup.ButtonClick += lup_ButtonClick;

        }
    }
}
